package rainingcatsdogs;

/**
 * Level class controls the difficulty settings for the game.
 * 
 * @author Group2
 */
public class Level {
	
	/**
	 * Holds all the string file paths for the music for the levels.
	 */
	private static final String[] LEVEL_MUSIC = {"/level_sunny.wav", "/level_beach.wav", "/level_forest.wav", "/level_pyramids.wav", "/level_beach.wav", "/level_skyscrapers.wav", "/level_lava.wav"};

	/**
	 * The current level the game is playing
	 */
	private int currLevel;

	/**
	 * The maximum number of levels in the game
	 */
	private int maxLevel;

	/**
	 * The difficulty ( easy medium hard) we are currently playing at
	 */
	private int difficulty;

	/**
	 * Canvas class that handles all the level parameters
	 */
	private CatsDogsCanvas game;

	/**
	 * Constructor for the level class
	 * 
	 * @param game
	 *            Game canvas reference
	 * @param difficulty
	 *            setting for level difficulty
	 * 
	 */
	public Level(CatsDogsCanvas game, int difficulty) {
		this.game = game;
		currLevel = 1;
		maxLevel = 7;
		this.difficulty = difficulty;
		setupLevels(difficulty);
	}

	/**
	 * Get the value of the current level
	 * 
	 * @return current level
	 */
	public int getCurrLevel() {
		return currLevel;
	}

	/**
	 * Get the value of the max level
	 * 
	 * @return max level
	 */
	public int getMaxLevel() {
		return maxLevel;
	}

	/**
	 * Set up levels for the game and manages advancement of levels
	 * 
	 * @return can go to the levels
	 */
	public boolean levelMove() {
		if (maxLevel > currLevel) {
			if (game.getEnemyKilled() >= this.currLevel * 25) {
				currLevel++;
				setupLevels(this.difficulty);
				this.game.updateLevelMusic(Level.LEVEL_MUSIC[this.currLevel-1]);
				return true;
			}
		}
		return false;

	}

	/**
	 * Set up Levels and difficulty values
	 * 
	 * @param difficulty
	 *            difficulty for each level
	 */
	private void setupLevels(int difficulty) {

		switch (difficulty) {

		// easy
		case 0:
			if (currLevel == 1) {
				game.setEnemySeed(0.3);
				game.setTerrainDamage(5);
				game.setTurretDamage(5);
				game.setLives(3);
				game.setMaxBombs(3);
				game.setEnemySpeed(1);
			} else {
				game.setEnemySeed(game.getEnemySeed() + 0.05);
				game.setEnemySpeed(game.getEnemySpeed() + 1);
			}

			break;

		// medium
		case 1:
			if (currLevel == 1) {
				game.setEnemySeed(0.5);
				game.setTerrainDamage(10);
				game.setTurretDamage(10);
				game.setLives(2);
				game.setMaxBombs(2);
				game.setEnemySpeed(2);
			} else {
				game.setEnemySeed(game.getEnemySeed() + 0.05);
				game.setEnemySpeed(game.getEnemySpeed() + 1);
			}
			break;

		// hard
		case 2:
			if (currLevel == 1) {
				game.setEnemySeed(0.65);
				game.setTerrainDamage(15);
				game.setTurretDamage(15);
				game.setLives(1);
				game.setMaxBombs(1);
				game.setEnemySpeed(3);
			} else {
				game.setEnemySeed(game.getEnemySeed() + 0.05);
				game.setEnemySpeed(game.getEnemySpeed() + 1);
			}

			break;

		}
	}

	/**
	 *Set the current level value
	 * 
	 * @param currlevel
	 */
	public void setCurrLevel(int currlevel) {
		this.currLevel = currlevel;
	}

}
